/**
 * Written by Timbot
 * V1.0, June 2007
 */
package com.as3.timbot.mvc
{
	import com.as3.timbot.mvc.IView;
	import com.as3.timbot.mvc.IModel;
	import com.as3.timbot.mvc.IController;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.EventDispatcher;
	
	public class AbstractView implements IView
	{
		private var __model:IModel;
		private var __controller:IController;
		
		public function AbstractView(model:IModel, controller:IController):void
		{
			setModel(model);
			EventDispatcher(getModel()).addEventListener(Event.CHANGE,onChange);
			 if (controller) {
				setController(controller);
			 }
		}
	/**
	* Sets the model this view is observing.
	*/
	public function setModel (m:IModel):void
	{
		//set the model here
		__model = m;
	};

	/**
	* Returns the model this view is observing.
	*/
	public function getModel ():IModel
	{
		//return the model here
		return __model;
	}

	/**
	* Sets the controller for this view.
	*/
	public function setController (c:IController):void
	{
		//set the controller here
		__controller = c;
		//establish the controller-view relationship
		getController().setView(this);
	}

	/**
	* Returns this view's controller.
	*/
	public function getController ():IController
	{
		//return the controller here
		return __controller ;
	}

	/**
	* Returns the default controller for this view.
	*/
	public function defaultController (model:IModel):IController
	{
		//return the default controller here - to be overridden by the sub-class
		trace ("the defaultController method for this class has not been overridden");
		return null;
	}
	/**
	* Action to take on change event received from model
	*/
	protected function onChange(e:Event):void
	{
		///override this instance method with functionality in the sub-class
	}
	
	}
}